package com.njtoyo.taxi.admin.rest.controller.business.operation_rule;

import cn.hutool.core.util.ObjectUtil;
import com.njtoyo.taxi.admin.aop.PassToken;
import com.njtoyo.taxi.admin.rest.presenter.business.operation_rule.DriverMarkScoreRulePresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.DriverMarkScoreRuleWrapper;
import com.njtoyo.taxi.admin.service.business.operation_rule.DriverMarkScoreRuleService;
import com.taxi.entity.common.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 司机阳光分
 */
@RestController
@RequestMapping("business/operation-rule/driver-mark-score")
public class DriverMarkScoreRuleController {

    @Autowired
    private DriverMarkScoreRuleService driverMarkScoreRuleService;

    @GetMapping("/list")
    @PassToken
    RestResult<List<DriverMarkScoreRulePresenter>> list(@RequestParam(value = "type", required = false) String type) {
        List<Integer> categorys = new ArrayList<>();
        if ("quality_score".equals(type)) {
            categorys.addAll(Arrays.asList(0, 1, 2));
        } else if ("travel_score".equals(type)) {
            categorys.addAll(Arrays.asList(3, 4, 5, 6));
            }
        return driverMarkScoreRuleService.getPageList(categorys);
    }


    @PostMapping("/update")
    RestResult update(@RequestBody DriverMarkScoreRuleWrapper wrapper) {
        if (ObjectUtil.isNull(wrapper.getId())) {
            return RestResult.failed("缺少必要参数:ID");
        }
        return driverMarkScoreRuleService.update(wrapper);
    }


}
